﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using VO.Business.Controllers;
using VO.Entities;

namespace VO.Web
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {

        private User _user;
        public User GetCurrentUser
        {
            get
            {
                if (_user == null)
                {
                    MembershipUser mUser = Membership.GetUser();
                    if (mUser != null)
                    {
                        Guid idMembership = new Guid(mUser.ProviderUserKey.ToString());
                        _user = UsersController.GetUserByIdMembership(idMembership);
                    }
                }
                return _user;
            }
        }


        public string MessageText
        {
            get
            {
                return lblMessages.Text;
            }
            set
            {
                lblMessages.Text = value;
                StringBuilder script = new StringBuilder();
                if (string.IsNullOrEmpty(value))
                {
                    //script.Append("$('#" + showHidePanel.ClientID + "').addClass('hidePanel').removeClass('showPanel');");
                    script.Append("$('#" + showHidePanel.ClientID + "').hide();");
                }
                else
                {
                    //script.Append("setTimeout('$(" + showHidePanel.ClientID +
                    //              ").addClass(\"hidePanel\").removeClass(\"showPanel\");', 3000);");
                    //script.Append("$('#" + showHidePanel.ClientID + "').addClass('showPanel').removeClass('hidePanel');");
                    script.Append("setTimeout('$(" + showHidePanel.ClientID +
                                  ").hide();', 3000);");
                    script.Append("$('#" + showHidePanel.ClientID + "').show();");
                    
                }
                //ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "showhideMessage", script.ToString(), true);
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showhideMessage", script.ToString(), true);

            }
        }


        public string MasterUserName
        {
            get
            {
                Label lblUserName = HeadLoginView.FindControl("lblUserName") as Label;
                if (lblUserName!=null)
                    return lblUserName.Text;
                return string.Empty;
            }
            set
            {
                Label lblUserName = HeadLoginView.FindControl("lblUserName") as Label;
                if (lblUserName != null)
                    lblUserName.Text = value;
                UpdatePanel pnlMasterUserName = HeadLoginView.FindControl("pnlMasterUserName") as UpdatePanel;
                if (pnlMasterUserName!=null)
                    pnlMasterUserName.Update();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (GetCurrentUser != null)
                {
                    Label lblUserName = HeadLoginView.FindControl("lblUserName") as Label;
                    lblUserName.Text = GetCurrentUser.PublicName;
                }

                showHidePanel.Attributes["class"] = "hidePanel";
            }
        }

    }
}
